﻿using System;
using System.Xml;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;
using System.Drawing;

namespace SBPweb.DNN.PhotoGallery
{
    /// <summary>
    /// Summary description for PhotoGalleryViewerInfo
    /// </summary>
    public class PhotoGalleryInfo : List<PhotoGallerySlideInfo>, ICloneable
    {
        
        #region Private fields

        private string pBasePath;
        private int? pPageIndex;
        private int? pPageSize;
        private int pPhotoGalleryId;
        private int pModuleId;
        private DateTime pCreatedDate;
        private string pTitle;
        private string pSource;

        private string pWidth = null;
        private string pHeight = null;
        private string pForeground = null;
        private string pBackground = null;
        private string pButtonBackground = null;
        private string pButtonForeground = null;
        private string pButtonBorder = null;
        private string pButtonPlayForeground = null;
        private string pCaptionBackground = null;
        private string pCaptionForeground = null;
        private string pContentBackground = null;
        private string pSelectedThumbnailBorder = null;
        private string pTrackerForeground = null;
        private decimal? pCaptionOpacity = null;
        private string pCaptionFont = null;
        private string pTrackerFont = null;
        private int? pBorderRadius = null;
        private int? pPadding = null;
        private bool? pCaptionVisible = null;
        private bool? pThumbnailsVisible = null;
        private bool? pTrackerVisible = null;
        private bool? pAutoPlay = null;

        #endregion

        #region Constructor logic

        public PhotoGalleryInfo()
            : this(string.Empty)
        {
        }

        public PhotoGalleryInfo(string basePath)
        {
            if (!string.IsNullOrEmpty(basePath))
            {
                pBasePath = basePath;
            }
        }

        public PhotoGalleryInfo(XmlDocument xml)
            : this(string.Empty)
        {
            XmlNode rootNode = xml.DocumentElement;
            XmlAttribute xaBasePath = rootNode.Attributes["baseUrl"];
            XmlAttribute xaPageIndex = rootNode.Attributes["page"];
            XmlAttribute xaPageSize = rootNode.Attributes["pageSize"];
            if (xaBasePath != null)
            {
                BasePath = xaBasePath.Value;
            }
            if (xaPageIndex != null)
            {
                PageIndex = Convert.ToInt32(xaPageIndex.Value);
            }
            if (xaPageSize != null)
            {
                PageSize = Convert.ToInt32(xaPageSize.Value);
            }

            foreach (XmlNode node in rootNode.ChildNodes)
            {
                this.Add(new PhotoGallerySlideInfo(node));
            }
        }

        #endregion

        #region Property accessors

        public int PhotoGalleryId
        {
            get
            {
                return pPhotoGalleryId;
            }
            set
            {
                pPhotoGalleryId = value;
            }
        }

        public int ModuleId
        {
            get
            {
                return pModuleId;
            }
            set
            {
                pModuleId = value;
            }
        }

        public string Title
        {
            get
            {
                return pTitle;
            }
            set
            {
                pTitle = value;
            }
        }

        public string Source
        {
            get
            {
                return pSource;
            }
            set
            {
                pSource = value;
            }
        }

        public string BasePath
        {
            get
            {
                return pBasePath;
            }
            set
            {
                pBasePath = value;
            }
        }

        public int? PageIndex
        {
            get
            {
                return pPageIndex;
            }
            set
            {
                pPageIndex = value;
            }
        }

        public int? PageSize
        {
            get
            {
                return pPageSize;
            }
            set
            {
                pPageSize = value;
            }
        }

        public DateTime CreatedDate
        {
            get
            {
                return pCreatedDate;
            }
            set
            {
                pCreatedDate = value;
            }
        }


        public string Width
        {
            get
            {
                return pWidth;
            }
            set
            {
                pWidth = value;
            }
        }

        public string Height
        {
            get
            {
                return pHeight;
            }
            set
            {
                pHeight = value;
            }
        }

        public string Background
        {
            get
            {
                return pBackground;
            }
            set
            {
                pBackground = value;
            }
        }

        public string Foreground
        {
            get
            {
                return pForeground;
            }
            set
            {
                pForeground = value;
            }
        }

        public string ButtonBackground
        {
            get
            {
                return pButtonBackground;
            }
            set
            {
                pButtonBackground = value;
            }
        }

        public string ButtonForeground
        {
            get
            {
                return pButtonForeground;
            }
            set
            {
                pButtonForeground = value;
            }
        }

        public string ButtonBorder
        {
            get
            {
                return pButtonBorder;
            }
            set
            {
                pButtonBorder = value;
            }
        }

        public string ButtonPlayForeground
        {
            get
            {
                return pButtonPlayForeground;
            }
            set
            {
                pButtonPlayForeground = value;
            }
        }

        public string CaptionBackground
        {
            get
            {
                return pCaptionBackground;
            }
            set
            {
                pCaptionBackground = value;
            }
        }

        public string CaptionForeground
        {
            get
            {
                return pCaptionForeground;
            }
            set
            {
                pCaptionForeground = value;
            }
        }

        public string ContentBackground
        {
            get
            {
                return pContentBackground;
            }
            set
            {
                pContentBackground = value;
            }
        }

        public string SelectedThumbnailBorder
        {
            get
            {
                return pSelectedThumbnailBorder;
            }
            set
            {
                pSelectedThumbnailBorder = value;
            }
        }

        public string TrackerForeground
        {
            get
            {
                return pTrackerForeground;
            }
            set
            {
                pTrackerForeground = value;
            }
        }

        public decimal? CaptionOpacity
        {
            get
            {
                return pCaptionOpacity;
            }
            set
            {
                pCaptionOpacity = value;
            }
        }

        public string CaptionFont
        {
            get
            {
                return pCaptionFont;
            }
            set
            {
                pCaptionFont = value;
            }
        }

        public string TrackerFont
        {
            get
            {
                return pTrackerFont;
            }
            set
            {
                pTrackerFont = value;
            }
        }

        public int? BorderRadius
        {
            get
            {
                return pBorderRadius;
            }
            set
            {
                pBorderRadius = value;
            }
        }

        public int? Padding
        {
            get
            {
                return pPadding;
            }
            set
            {
                pPadding = value;
            }
        }

        public bool? CaptionVisible
        {
            get
            {
                return pCaptionVisible;
            }
            set
            {
                pCaptionVisible = value;
            }
        }

        public bool? ThumbnailsVisible
        {
            get
            {
                return pThumbnailsVisible;
            }
            set
            {
                pThumbnailsVisible = value;
            }
        }

        public bool? TrackerVisible
        {
            get
            {
                return pTrackerVisible;
            }
            set
            {
                pTrackerVisible = value;
            }
        }

        public bool? AutoPlay
        {
            get
            {
                return pAutoPlay;
            }
            set
            {
                pAutoPlay = value;
            }
        }

        #endregion

        #region Methods

        public object Clone()
        {
            return Clone(0, this.Count);
        }

        public PhotoGalleryInfo Clone(int index, int count)
        {
            PhotoGalleryInfo slides = new PhotoGalleryInfo(BasePath);
            slides.AddRange(this.GetRange(index, count));
            return slides;
        }

        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("<slides baseUrl=\"{0}\"", BasePath);
            if (PageIndex.HasValue)
            {
                sb.AppendFormat(" page=\"{0}\"", PageIndex.Value);
            }
            if (PageSize.HasValue)
            {
                sb.AppendFormat(" pageSize=\"{0}\"", PageSize.Value);
            }
            sb.AppendLine(">");
            foreach (PhotoGallerySlideInfo slide in this)
            {
                sb.AppendLine(slide.ToString());
            }
            sb.Append("</slides>");
            return sb.ToString();
        }

        #endregion

    }
}